<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
	//session_start();
	/*$_SESSION['IsLogin']=true;
	$_SESSION['UserName']='lvhung';*/
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shoppinghere</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Mạng xã hội mua bán siêu việt | ShoppingHere.com</title>
		<link rel="stylesheet" href="../css/reset.css" type="text/css" />
		<link rel="stylesheet" href="../css/common.css" type="text/css" />
		<link rel="stylesheet" href="../css/home.css" type="text/css" />
		<script src="../scripts/jquery-1.5.2.min.js"></script>
		<script src="../scripts/common.js"></script>
		<link rel="stylesheet" href="../css/MenuMatic.css" type="text/css" media="screen" charset="utf-8" />
		<link rel="stylesheet" href="../css/MenuMatic2.css" type="text/css" media="screen" charset="utf-8" />
        <style type="text/css">
			#seller-details .content {
				overflow: hidden;
			}
		
			#seller-details .seller-info {
				overflow: hidden;
			}
		
			#seller-details .seller-info .image {
				float: left;
				margin-right: 20px;
			}
			
			#seller-details .seller-info .image img {
				width: 150px;
				-moz-border-radius: 5px;
				border-radius: 5px;
			}
			
			#seller-details .seller-info .username {
				font-weight: bold;
				font-size: 20px;
				color: #9BC022;
			}
			
			#seller-details .seller-info table {
				margin-top: 10px;
			}
			
			#seller-details .seller-info td {
				padding-top: 3px;
				padding-bottom: 3px;
				padding-right: 20px;
			}
			
			#seller-details .seller-events {
				margin-top: 10px;
				margin-bottom: 10px;
				
			}
			
			#seller-details .seller-events .seller-events-title {
				font-weight: bold;
				font-size: 18px;
				margin-bottom: 10px;
				color: #9BC022;
				border-bottom: 1px solid #9BC022;
				padding-bottom: 5px;
			}
			
			#seller-details .seller-events .seller-events-item {
				overflow: hidden;
				margin-bottom: 20px;
			}
			
			#seller-details .seller-events .seller-events-item .image-col {
				float: left;
				margin-right: 10px;
			}
			
		
			#seller-details .seller-events .seller-events-item .name {
				font-weight: bold;
				font-size: 15px;
				margin-bottom: 3px;
				color: #9BC022;
			}
			
			#seller-details .seller-events .seller-events-item .start-date {
				margin-bottom: 3px;
			}
			
			#seller-details .seller-events .seller-events-item .end-date {
				margin-bottom: 3px;
			}
			
			#seller-details .seller-events .pager {
				text-align: center;
			}
			
			#seller-details .seller-events .pager ul li {
				display: inline;
			}
			
			#seller-details .seller-events .pager ul li.selected {
				color: #9BC022;
				font-weight: bold;
			}
			
		</style>
        <script type="text/javascript" language="javascript">
			var xmlhttp;
			var xmlhttp1;
			function createXMLHTTPRequest()
			{
				if(window.XMLHttpRequest)
				{
					return new XMLHttpRequest();
				}
				else if(window.ActiveXObject)
				{
					return new ActiveXObject("microsoft.XMLHTTP");
				}
				return null;
			}
			function loadSuKien(magh)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showSuKien;
				var serverUrl="../BUS/xlSuKienBUS.php?magh="+magh;
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function indexClick(i,magh)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showSuKien;
				var serverUrl="../BUS/xlSuKienBUS.php?magh="+magh+"&curPage="+i;
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function likeClick(like,curPage,magh,mask)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showSuKien;
				var serverUrl="../BUS/xlSuKienBUS.php?magh="+magh+"&curPage="+curPage+"&like="+like+"&mask="+mask;
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function commentClick(j)
			{
				var div=document.getElementById("comment"+j);
				var class=div.className;
				if(class=="comment")
				{
					div.className="visible-comment";
				}
				else
				{
					div.className="comment";
				}
			}
			function commentspClick(j)
			{
				var div=document.getElementById("commentsp"+j);
				var class=div.className;
				if(class=="comment")
				{
					div.className="visible-comment";
				}
				else
				{
					div.className="comment";
				}
			}
			function cancelBinhLuan(j)
			{
				var div=document.getElementById("comment"+j);
				div.className="comment";
				document.getElementById("text"+j).value="";
			}
			function cancelBinhLuansp(j)
			{
				var div=document.getElementById("commentsp"+j);
				div.className="comment";
				document.getElementById("sanpham"+j).value="";
			}
			function submitBinhLuan(j,mask)
			{
				var nd=document.getElementById("text"+j).value;
				if(nd=="")
				{
					alert("Chưa nhập bình luận của bạn");
					return;
				}
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showSubmit;
				var serverUrl="../BUS/xlComment.php?mask="+mask+"&nd="+nd;
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function submitBinhLuansp(j,masp)
			{
				var nd=document.getElementById("sanpham"+j).value;
				if(nd=="")
				{
					alert("Chưa nhập bình luận của bạn");
					return;
				}
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showSubmitsp;
				var serverUrl="../BUS/xlThemBinhLuanSP.php?masp="+masp+"&nd="+nd;
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function submitNhanTin(magh)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showLikeGianHang;
				var serverUrl="../BUS/xlNhanTinBUS.php?magh="+magh+"&type=1";
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
				
			}
			function huyNhanTin(magh)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showLikeGianHang;
				var serverUrl="../BUS/xlNhanTinBUS.php?magh="+magh+"&type=0";
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function likeghClick(magh)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showLikeGianHang;
				var serverUrl="../BUS/xlNhanTinBUS.php?magh="+magh+"&like=1";
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function unlikeClick(magh)
			{
				xmlhttp=createXMLHTTPRequest();
				xmlhttp.onreadystatechange=showLikeGianHang;
				var serverUrl="../BUS/xlNhanTinBUS.php?magh="+magh+"&like=0";
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
			}
			function loadSanPham(magh)
			{
				xmlhttp1=createXMLHTTPRequest();
				xmlhttp1.onreadystatechange=showListSanPham;
				var serverUrl="../BUS/xlSanPhamBUS.php?magh="+magh;
				xmlhttp1.open("get",serverUrl,"true");
				xmlhttp1.send(null);
			}
			function indexspClick(i,magh)
			{
				xmlhttp1=createXMLHTTPRequest();
				xmlhttp1.onreadystatechange=showListSanPham;
				var serverUrl="../BUS/xlSanPhamBUS.php?magh="+magh+"&curPage="+i;
				xmlhttp1.open("get",serverUrl,"true");
				xmlhttp1.send(null);
			}
			function themVaoGioHang(j,masp,dongia,soluongcon)
			{
				
				//donvitinh=1;
				//soluongcon=1;
				var soluong=document.getElementById("txtSoLuong"+j).value;
				var donvitinh=document.getElementById("label"+j).innerHTML;
				if(soluong=="")
				{
					alert("Chưa nhập số lượng cần mua");
					return;
				}
				var test=kiemTraLaSo(soluong);
				if(test==false)
				{
					alert("Số lượng cần mua phải là số nguyên");
					return;
				}
				/*if(soluong>soluongcon)
				{
					alert("Số lượng bạn mua lớn, xin liên hệ trực tiếp với chúng tôi để được đáp ứng tốt nhất");
					return;
				}*/
				//Kiem tra so luong la so ?
				xmlhttp1=createXMLHTTPRequest();
				xmlhttp1.onreadystatechange=showThem;
				var serverUrl="../BUS/xlGioHangBUS.php?masp="+masp+"&type=1&soluong="+soluong +"&dongia="+dongia+"&donvitinh="+donvitinh+"&soluongcon="+soluongcon;
				xmlhttp1.open("get",serverUrl,"true");
				xmlhttp1.send(null);
				
			}
			function kiemTraLaSo(so)
			{
				var n=so.length;
				for( var i=0;i<n;i++)
				{
					if(so[i]<"0" || so[i]>"9")
					{
						return false;
						
					}
				}
				return true;
			}
			function showThem()
			{
				if(xmlhttp1.readyState==4 && xmlhttp1.status==200)
				{
					var result=xmlhttp1.responseText;
					//alert(result);
					//document.getElementById("ls").innerHTML=result;
					if(result=="true")
					{
						alert("Đã thêm vào giỏ hàng");
					}
					
				}
			}
			function showListSanPham()
			{
				if(xmlhttp1.readyState==4 && xmlhttp1.status==200)
				{
					var result=xmlhttp1.responseText;
					var div=document.getElementById("showListSanPham");
					div.innerHTML=result;
				}
			}
			
			function showLikeGianHang()
			{
				if(xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var result=xmlhttp.responseText;
					var div=document.getElementById("showlikegianhang");
					div.innerHTML=result;
				}
			}
			function showSubmit()
			{
				if(xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var result=xmlhttp.responseText;
					if(result=="false")
					{
						alert("Bình luận chưa thể lưu được");
					}
					else
					{
						alert("Bạn đã đăng bình luận thành công");
						window.location="XemBinhLuanSK.php?mask="+result;
					}
				}
			}
			function showSubmitsp()
			{
				if(xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var result=xmlhttp.responseText;
					if(result=="false")
					{
						alert("Bình luận chưa thể lưu được");
					}
					else
					{
						alert("Bạn đã đăng bình luận thành công");
						window.location="chitietsanpham.php?masp="+result;
					}
				}
			}
			
			function showSuKien()
			{
				if(xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var div=document.getElementById("showSuKien");
					var result=xmlhttp.responseText;
					div.innerHTML=result;
				
				}
			}
		</script>
	</head>
	<body>
		<div id="page">
			<?php
				include_once("../webconfig.php");
				
				include_once("../DAO/DataHelper.php");
				include_once("../DAO/TaiKhoan_DAO.php");
				include_once("../DAO/DanhMucSanPham_DAO.php");
				include_once("../DAO/SanPham_DAO.php");
				include_once("../UserControl/header.php");
				include_once("../DAO/GianHangDTO.php");
				include_once("../DAO/GianHangDAO.php");
				include_once("../DAO/SuKienDTO.php");
				include_once("../DAO/SuKienDAO.php");
				include_once("../DAO/SanPhamDAO.php");
				include_once("../DAO/SanPhamDTO.php");
				
			?>
			<div id="content">
				<?php
					require("../UserControl/DanhMucLoaiSanPham.php");
				?>
				<div id="seller-details" class="block layout-2col-col2" style="width:830px">
				<div class="title"><h4>Chi tiết gian hàng</h4></div>
				<div class="content">
					<div class="seller-info">
                    <?php
						if(isset($_REQUEST['magh']))
						{
							$magh=$_REQUEST['magh'];
							$result=GianHangDAO::LayThongTinGianHangVaChuTheoMaGH($magh);
							$soluong=GianHangDAO::DemSoNguoiThichGianHang($magh);
							if($result!=null)
							{
								echo("<div class='col'>
								<div class='image'>
									<img src='../images/$result->tk_avatar' />
								</div>
								<div class='info'>
									<p class='username'>$result->gh_ten</p>
									<table>
										<tbody>
											<tr>
												<td>
													<label>Họ tên: </label><span>$result->tk_ho_ten</span>
												</td>
												<td>
													<label>Điện thoại: </label><span>$result->tk_dien_thoai</span>
												</td>
											</tr>
											<tr>
												<td>
													<label>Giới tính: </label><span>");
													
													if($result->tk_gioi_tinh==1)
													{
														echo("Nam");
													}
													else
														echo("Nữ");
													echo("</span>
												</td>
												<td>
													<label>Ngày tạo: </label><span>$result->gh_ngay_tao</span>
												</td>
											</tr>
											<tr>
												<td>
													<label>Email: </label><span>$result->tk_email</span>
												</td>
												
											</tr>
											<tr>
												<td>
													<label>Địa chỉ: </label><span>$result->gh_dia_chi</span>
												</td>
												
											</tr>
										</tbody>
									</table>
								</div>
								</div>");
								if(isset($_SESSION['IsLogin'])&& $_SESSION['IsLogin']==true)
								{
									$username=$_SESSION['UserName'];
								
									echo("<p align='center' id='showlikegianhang' class='like'>");
									if(GianHangDAO::KiemTraDangKyNhanTin($magh,$username)<=0)
									{
										echo("<input name='button' type='button' class='buy btn' value='Đăng kí nhận tin' onClick='submitNhanTin($magh);'/>  ");
									}
									else
									{
										echo("<input name='button' type='button' class='buy btn' value='Hủy đăng kí nhận tin' onClick='huyNhanTin($magh);'/>  ");
									}
									if(GianHangDAO::KiemTraThichGianHang($magh,$username)<=0)
									{
										echo("<input name='button' type='button' class='buy btn' value='Thích gian hàng' onClick='likeghClick($magh);'/>");
									}
									else
									{
										echo("<input name='button' type='button' class='buy btn' value='Không thích gian hàng nữa' onClick='unlikeClick($magh);'/>");
									}
									echo("</p>");
								}
								else
								{
									echo("<p align='center' id='showlikegianhang' class='like'><label>Đăng nhập để đăng ký nhận tin</label>  |  <label style='color:red;font-weight:bold'>Đăng nhập để thích</label></p>");
								}
								
							}
							else
							{
								echo("<script type='text/javascript' language='javascript'>alert('Gian hàng hông tồn tại');</script>");
								header("Location: ../index.php");
							}
						}
						else
						{
							header("Location: ../index.php");
						}
						?>
                        
					</div>
                    <br />
                    <br />
					<div class="seller-events">
						<p class="seller-events-title">Sự kiện</p>
                        
                        <?php
						echo("<script type='text/javascript' language='javascript'>
							loadSuKien($magh);
                        </script>");
						echo("<div class='seller-events-item' id='showSuKien'>

						</div>");
						?>
					
						
					</div>
<?php
$masp = "1";
$result = SanPhamDAO::ChiTietSanPham($masp);
?>		
					<div class="seller-events">
					<p class="seller-events-title">Sản phẩm</p>
                    <?php
						echo("<script type='text/javascript' language='javascript'>
							loadSanPham($magh);
                        </script>");
					?>
                    <div id="showListSanPham">
                    
                        
                    <div>
				</div>					
				</div>
			</div>
			<div id="ls">
			</div>
				<?php
					
					//require("../DAO/GioHangDTO.php");
				/*	class GioHangDTO
					{
						public $masp;
						public $soluong;
						public $dongia;
						public $donvitinh;
						public $tongtien;
					}
					if(isset($_SESSION['Cart'])&& $_SESSION['Cart']!=null)
					{
						$array=$_SESSION['Cart'];
						if(count($array))
						{
							foreach($array as $cart)
							{
								echo("$cart->masp;
								$cart->soluong;
								$cart->dongia;
								$cart->donvitinh;
								$cart->tongtien;");
							}
						}
					}*/

				?>
			</div>
			<?php
				require("../UserControl/footer.php");
			?>
		</div>
	</body>
</html>